﻿using UnityEngine;
using System.Collections;
namespace UI
{
    public class ItemSelect : MonoBehaviour
    {
        #region 升级
        public GameObject LevelUpSelect;//选中时的黄色的图片
        public GameObject levelUp_select;//选中时的小图标
        public GameObject levelUp_noSelect;//没选中时的小图标
        public GameObject levelUp_word;//名字
        #endregion

        #region 天赋
        public GameObject TalentSelect;
        public GameObject talent_select;
        public GameObject talent_noSelect;
        public GameObject talent_word;
        #endregion

        #region 训练
        public GameObject TrainSelect;
        public GameObject train_select;
        public GameObject train_noSelect;
        public GameObject train_word;
        #endregion

        #region 突破
        public GameObject BreakThroughSelect;
        public GameObject breakthrough_select;
        public GameObject breakthrough_noSelect;
        public GameObject breakthrough_word;
        #endregion

        #region 指向
        public GameObject levelUp;
        public GameObject talent;
        public GameObject train;
        public GameObject breakThrough;
        #endregion

        bool levelUpActive = true;

        /// <summary>
        /// 升级隐藏或显示时位置处理
        /// </summary>
        public void UpdateMode(bool mode)
        {
            if(mode != levelUpActive)
            {
                levelUpActive = mode;
                MoveUpOrDown(TalentSelect, mode);
                MoveUpOrDown(talent_select, mode);
                MoveUpOrDown(talent_noSelect, mode);
                MoveUpOrDown(talent_word, mode);
                MoveUpOrDown(talent, mode);

                MoveUpOrDown(TrainSelect, mode);
                MoveUpOrDown(train_select, mode);
                MoveUpOrDown(train_noSelect, mode);
                MoveUpOrDown(train_word, mode);
                MoveUpOrDown(train, mode);

                MoveUpOrDown(BreakThroughSelect, mode);
                MoveUpOrDown(breakthrough_select, mode);
                MoveUpOrDown(breakthrough_noSelect, mode);
                MoveUpOrDown(breakthrough_word, mode);
                MoveUpOrDown(breakThrough, mode);
            }
        }

        void MoveUpOrDown(GameObject obj,bool isDown)
        {
            int dy = isDown ? -59 : 59;
            Vector3 pos = obj.transform.localPosition;
            obj.transform.localPosition = new Vector3(pos.x, pos.y + dy, pos.z);
        }

        /// <summary>
        /// 升级
        /// </summary>
        public void SelectLevel()
        {
            NoSelectActive();
            AllNotActive();
            LevelUpSelect.SetActive(levelUpActive);
            levelUp_select.SetActive(levelUpActive);
            levelUp_noSelect.SetActive(false);
            levelUp.SetActive(levelUpActive);
        }
        /// <summary>
        /// 天赋
        /// </summary>
        public void SelectTalent()
        {
            NoSelectActive();
            AllNotActive();
            talent_select.SetActive(true);
            TalentSelect.SetActive(true);
            talent_noSelect.SetActive(false);
            talent.SetActive(true);

        }
        /// <summary>
        /// 选中训练
        /// </summary>
        public void SelectTrain()
        {
            NoSelectActive();
            AllNotActive();
            TrainSelect.SetActive(true);
            train_select.SetActive(true);
            train_noSelect.SetActive(false);
            train.SetActive(true);
        }
        /// <summary>
        /// 选中突破
        /// </summary>
        public void SelectBreakThrough()
        {
            NoSelectActive();
            AllNotActive();
            BreakThroughSelect.SetActive(true);
            breakthrough_select.SetActive(true);
            breakthrough_noSelect.SetActive(false);
            breakThrough.SetActive(true);
        }
        
        /// <summary>
        /// 全部不显示
        /// </summary>
        private void AllNotActive()
        {
            levelUp_word.SetActive(levelUpActive);
            LevelUpSelect.SetActive(false);
            levelUp_select.SetActive(false);
            levelUp.SetActive(false);
            
            TalentSelect.SetActive(false);
            talent_select.SetActive(false);
            talent.SetActive(false);
           
            TrainSelect.SetActive(false);
            train_select.SetActive(false);
            train.SetActive(false);
          
            BreakThroughSelect.SetActive(false);
            breakthrough_select.SetActive(false);
            breakThrough.SetActive(false);
        }
        /// <summary>
        /// 未被选中该显示的小图标
        /// </summary>
        private void NoSelectActive() 
        {
            levelUp_noSelect.SetActive(true && levelUpActive);
            talent_noSelect.SetActive(true);
            train_noSelect.SetActive(true);
            breakthrough_noSelect.SetActive(true);


        }
    }


}